package com.oscar.ehome.presenter;

import com.oscar.ehome.bean.messageBean.MessageDetailBean;
import com.oscar.ehome.bean.messageBean.MessageLeveBean;
import com.oscar.ehome.bean.messageBean.MessagesBean;
import com.oscar.ehome.bean.pagebean.HdBean;
import com.oscar.ehome.model.HttpModel;
import com.oscar.ehome.model.HttpModelImple;
import com.oscar.ehome.model.OnHttpListener;
import com.oscar.ehome.view.messageview.view.IssueMessageView;
import com.oscar.ehome.view.pageview.view.HdView;
import com.oscar.ehome.view.messageview.view.MessageDetailView;
import com.oscar.ehome.view.messageview.view.MessageListView;

/**
 * Created by oscar
 * author: MengWanhe
 * date: On 2017/7/4
 * 消息列表
 */

public class MessageListPreaenter extends BasePresenter {

    HttpModel httpModel;
    MessageListView listView;
    MessageDetailView detailView;
    IssueMessageView issueMessageView;


    public MessageListPreaenter(MessageListView listView) {
        this.listView = listView;
        httpModel = new HttpModelImple();
    }

    public MessageListPreaenter(MessageDetailView detailView) {
        this.detailView = detailView;
        httpModel = new HttpModelImple();
    }


    public MessageListPreaenter(IssueMessageView issueMessageView) {
        this.issueMessageView = issueMessageView;
        httpModel = new HttpModelImple();
    }

    /**
     * 获取消息列表
     */
    public void messagelist(String token, String pageNo, String pageSize, String query, String types, String readFlag) {
        httpModel.getMessageList(token, pageNo, pageSize, query, types, readFlag, new OnHttpListener<MessagesBean>() {
            @Override
            public void onSuccess(MessagesBean obj) {
                if (listView != null)
                    listView.getMessageList(obj);
            }

            @Override
            public void onError(String msg) {
                if (listView != null)
                    listView.erry(msg);
            }

            @Override
            public void onFailure() {
                if (listView != null)
                    listView.erroy();
            }
        });
    }


    /**
     * 获取消息详情列表
     */
    public void messagedetailist(String token, String id) {
        httpModel.getMessageDetail(token, id, new OnHttpListener<MessageDetailBean>() {
            @Override
            public void onSuccess(MessageDetailBean obj) {
                if (detailView != null)
                    detailView.getMessageDetail(obj);
            }

            @Override
            public void onError(String msg) {
                if (detailView != null)
                    detailView.erry(msg);
            }

            @Override
            public void onFailure() {
                if (detailView != null)
                    detailView.erroy();
            }
        });
    }

    /**
     * 发布消息
     */
    public void setMessage(String token, String title, String content, String foreignIds) {
        httpModel.setMesage(token, title, content, foreignIds, new OnHttpListener<String>() {
            @Override
            public void onSuccess(String obj) {
                if (issueMessageView != null)
                    issueMessageView.setMessage(obj);
            }

            @Override
            public void onError(String msg) {
                if (issueMessageView != null)
                    issueMessageView.erry(msg);
            }

            @Override
            public void onFailure() {
                if (issueMessageView != null)
                    issueMessageView.erroy();
            }
        });
    }

    /**
     * 获取消息内职级列表
     */
    public void getMessageLeve(String token) {
        httpModel.getMesageLeve(token, new OnHttpListener<MessageLeveBean>() {
            @Override
            public void onSuccess(MessageLeveBean obj) {
                if (issueMessageView != null)
                    issueMessageView.getMessageLeve(obj);
            }

            @Override
            public void onError(String msg) {
                if (issueMessageView != null)
                    issueMessageView.erry(msg);
            }

            @Override
            public void onFailure() {
                if (issueMessageView != null)
                    issueMessageView.erroy();
            }
        });
    }


    public void onDestory() {
        listView = null;
        detailView = null;
        issueMessageView = null;
    }

}
